﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class FormulaireRecette : System.Web.UI.UserControl
    {
        protected const string connectionString = @"Provider=SQLOLEDB;server=forma1614;Database=magicrecettes;User ID=magicrecettes;Password=cook;Trusted_Connection=False";
        protected const string query = "SELECT * FROM Ingredient";

        SqlConnection con;
        //Here we declare the parameter which we have to use in our application
        SqlCommand cmd = new SqlCommand();
        SqlParameter sp1 = new SqlParameter();
        SqlParameter sp2 = new SqlParameter();
        SqlParameter sp3 = new SqlParameter();
        SqlParameter sp4 = new SqlParameter();
        SqlParameter sp5 = new SqlParameter();
        SqlParameter sp6 = new SqlParameter();
        SqlParameter sp7 = new SqlParameter();
        SqlParameter sp8 = new SqlParameter();


        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                OleDbDataAdapter da = new OleDbDataAdapter(query, connectionString);
                da.TableMappings.Add("Table", "Ingredient");
                DataSet ds = new DataSet();
                da.Fill(ds);

                System.Text.StringBuilder sb = new System.Text.StringBuilder();

            }
        }

        protected void TypePlat_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtDessert.Checked)
            {
                lblTest.Text = rbtDessert.Text;
            }

            if (rbtPlat.Checked)
            {
                lblTest.Text = rbtPlat.Text;
            }
            if (rbtEntree.Checked)
            {
                lblTest.Text = rbtEntree.Text;
            }
        }
        protected void btnSuivant_Click(object sender, EventArgs e)
        {


            con = new SqlConnection("server=FORMA1614;Database=magicrecettes;User ID=magicrecettes;Password=cook;Trusted_Connection=False");

            cmd = new SqlCommand("dbo.CreateReceipt", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            //Enregistrement En-tête Recette
            cmd.Parameters.Add("@Nom", SqlDbType.VarChar, 50).Value = txtNom.Text;
            cmd.Parameters.Add("@Sous_Titre", SqlDbType.VarChar, 50).Value = txtSousTitre.Text;
            cmd.Parameters.Add("@Nb_Personnes", SqlDbType.Int).Value = txtNombrePersonnes.Text;
            cmd.Parameters.Add("@Tps_Preparation", SqlDbType.Int).Value = txtTempsPreparation.Text;
            cmd.Parameters.Add("@Tps_Cuisson", SqlDbType.Int).Value = txtTempsCuisson.Text;
            cmd.Parameters.Add("@Difficulte", SqlDbType.Int).Value = ddlDifficulte.SelectedValue;
            cmd.Parameters.Add("@Preparation", SqlDbType.Text).Value = txtPreparation.Text;
            cmd.Parameters.Add("@Realisation", SqlDbType.Text).Value = txtRealisation.Text;

            Session["Nom_Recette"] = txtNom.Text;

            try
            {
                cmd.ExecuteNonQuery();

                txtNom.Text = string.Empty;
                txtSousTitre.Text = string.Empty;
                txtNombrePersonnes.Text = string.Empty;
                txtTempsPreparation.Text = string.Empty;
                txtTempsCuisson.Text = string.Empty;
                txtPreparation.Text = string.Empty;
                txtRealisation.Text = string.Empty;
                ddlDifficulte.SelectedIndex = 0;
            }
            catch (SqlException ex)
            {
                Response.Write(ex.Message);
            }
            con.Close(); //On ferme.


            Response.Redirect("~/NouvelleRecette2.aspx", true);
        }

    }
}